package org.amphiprion.rfreplayanalyser.parser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Replay {
	private String filename;
	private ReplayInfo info;
	private List<Driver> drivers = new ArrayList<Driver>();
	private List<Score> scoreEvolution = new ArrayList<Score>();
	private List<DriverLocation> driverLocations = new ArrayList<DriverLocation>();
	private List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
	private List<StopToDriveEvent> stopEvents = new ArrayList<StopToDriveEvent>();
	private List<DamageEvent> damageEvents = new ArrayList<DamageEvent>();
	private List<PitEvent> pitEvents = new ArrayList<PitEvent>();
	private List<TouchEvent> touchEvents = new ArrayList<TouchEvent>();
	private List<StartingLightEvent> startingLightEvents = new ArrayList<StartingLightEvent>();
	private List<OffRoadEvent> offRoadEvents = new ArrayList<OffRoadEvent>();
	private HashMap<Long, List<DriverLocation>> locationsPerDriver = new HashMap<Long, List<DriverLocation>>();
	public float minWithToTriggerTouchEvent;
	public float minHeightToTriggerTouchEvent;
	private Track track;
	public String aiwFilename;

	/**
	 * @return the filename
	 */
	public String getFilename() {
		return filename;
	}

	/**
	 * @param filename
	 *            the filename to set
	 */
	public void setFilename(String filename) {
		this.filename = filename;
	}

	/**
	 * @return the info
	 */
	public ReplayInfo getInfo() {
		return info;
	}

	/**
	 * @param info
	 *            the info to set
	 */
	public void setInfo(ReplayInfo info) {
		this.info = info;
	}

	/**
	 * @return the drivers
	 */
	public List<Driver> getDrivers() {
		return drivers;
	}

	/**
	 * @param driver
	 *            the driver to set
	 */
	public void addDriver(Driver driver) {
		this.drivers.add(driver);
	}

	/**
	 * @return the scoreEvolution
	 */
	public List<Score> getScoreEvolution() {
		return scoreEvolution;
	}

	/**
	 * @param score
	 *            the score to set
	 */
	public void addScoreEvolution(Score score) {
		this.scoreEvolution.add(score);
	}

	/**
	 * @return the driverLocations
	 */
	public List<DriverLocation> getDriverLocations() {
		return driverLocations;
	}

	/**
	 * @param driverLocation
	 *            the driverLocation to set
	 */
	public void addDriverLocation(DriverLocation driverLocation) {
		this.driverLocations.add(driverLocation);
		List<DriverLocation> locs = locationsPerDriver.get(driverLocation.getDriverId());
		if (locs == null) {
			locs = new ArrayList<DriverLocation>();
			locationsPerDriver.put(driverLocation.getDriverId(), locs);
		}
		locs.add(driverLocation);
	}

	public List<DriverLocation> getDriverLocations(long driverId) {
		return locationsPerDriver.get(driverId);
	}

	/**
	 * @return the checkpoints
	 */
	public List<Checkpoint> getCheckpoints() {
		return checkpoints;
	}

	/**
	 * @param checkpoint
	 *            the checkpoint to set
	 */
	public void addCheckpoint(Checkpoint checkpoint) {
		this.checkpoints.add(checkpoint);
	}

	public void addStopToDriveEvent(StopToDriveEvent evt) {
		stopEvents.add(evt);
	}

	public List<StopToDriveEvent> getStopEvents() {
		return stopEvents;
	}

	public void addDamageEvent(DamageEvent evt) {
		damageEvents.add(evt);
	}

	public List<DamageEvent> getDamageEvents() {
		return damageEvents;
	}

	public void addPitEvent(PitEvent evt) {
		pitEvents.add(evt);
	}

	public List<PitEvent> getPitEvents() {
		return pitEvents;
	}

	public void addTouchEvent(TouchEvent evt) {
		touchEvents.add(evt);
	}

	public List<TouchEvent> getTouchEvents() {
		return touchEvents;
	}

	public Driver getDriver(long driverId) {
		for (Driver d : drivers) {
			if (d.getDriverId() == driverId) {
				return d;
			}
		}
		return null;
	}

	public void addStartingLight(StartingLightEvent sl) {
		startingLightEvents.add(sl);
	}

	public List<StartingLightEvent> getStartingLightEvents() {
		return startingLightEvents;
	}

	public void addOffRoadEvent(OffRoadEvent ore) {
		offRoadEvents.add(ore);
	}

	public List<OffRoadEvent> getOffRoadEvents() {
		return offRoadEvents;
	}

	/**
	 * @return the track
	 */
	public Track getTrack() {
		return track;
	}

	/**
	 * @param track
	 *            the track to set
	 */
	public void setTrack(Track track) {
		this.track = track;
	}

}
